package people.paper.tv.activity.home.modual.rmrb.view.impl;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;

import com.skyworth.ui.newrecycleview.NewRecycleAdapterItem;
import com.skyworth.util.Util;

import people.paper.tv.R;
import people.paper.tv.activity.home.modual.rmrb.view.data.DailyData;

public class DailyItemView extends ItemView implements NewRecycleAdapterItem<DailyData.ReportData> {
    DailyData.ReportData mdata;
    ImageView playingView;

    public DailyItemView(@NonNull Context context, boolean layout) {
        super(context, layout);
        playingView = new ImageView(context);
        LayoutParams play_params = new LayoutParams(LayoutParams.WRAP_CONTENT, Util.Div(120), Gravity.CENTER_VERTICAL);
        play_params.leftMargin = Util.Div(12);
        contentLayout.addView(playingView, play_params);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public void onUpdateData(DailyData.ReportData data, int position) {
        this.mdata = data;
        curPosition = position;
        if (data == null) {
            return;
        }
    }

    @Override
    public void clearItem() {

    }

    @Override
    public void refreshUI() {
        if (mdata != null) {
            Log.i("rmrb", "DailyData DailyItemView:"+mdata.title);
            title.setText(mdata.title);
            onFocusChange(hasFocus());
        }
    }

    @Override
    public void onClickAction() {
        if(mdata != null) {
            mdata.onClick.run();
        }
    }

    @Override
    public void onFocusChange(boolean hasFocus) {
        title.setSelected(hasFocus);
        if(hasFocus){
            if(mdata.isCurSelected)
                playingView.setImageResource(R.mipmap.audio_play_focus);
            else
                playingView.setImageBitmap(null);
            setBackgroundColor(getResources().getColor(R.color.content_selected_bg));
            title.setTextColor(getResources().getColor(R.color.title_focus));
        }else {
            if(mdata.isCurSelected){
                setBackground(null);
                playingView.setImageResource(R.mipmap.audio_play_select);
                title.setTextColor(getResources().getColor(R.color.title_selected));
            }else {
                setBackground(null);
                playingView.setImageBitmap(null);
                title.setTextColor(getResources().getColor(R.color.title_unfocus));
            }
        }
    }

    @Override
    public void destroy() {

    }
}
